package com.example.springbootjavafx.view;


import de.saxsys.mvvmfx.FxmlView;
import de.saxsys.mvvmfx.InjectViewModel;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class EditView implements FxmlView<EditViewModel> {

    @FXML
    public TextField userName,userId,userAddress;
    @FXML
    private Button saveButton;


    @InjectViewModel
    private EditViewModel editViewModel;

    private Stage showDialog;

    @FXML
    public void onClickSave(ActionEvent actionEvent) {
        editViewModel.saveUser();
        // 关闭对话框
        this.showDialog.close();

    }


    public void initialize() {
//        log.info("-----------------------> user :{}",editViewModel.userDetailScope.getSelectedUser());

        userId.textProperty().bindBidirectional(editViewModel.userDetailScope.getIdProperty());
        userName.textProperty().bindBidirectional(editViewModel.userDetailScope.getNameProperty());
        userAddress.textProperty().bindBidirectional(editViewModel.userDetailScope.getAddressProperty());
    }

    public void setDisplayingStage(Stage showDialog) {
        this.showDialog = showDialog;
    }


}
